package com.example.gss.mapper;

import com.example.gss.entity.ResearchAchievement;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ResearchAchievementMapper {

    // 查询所有科研成果
    @Select("SELECT * FROM researchachievement")
    List<ResearchAchievement> selectAll();

    // 根据ID查询
    @Select("SELECT * FROM researchachievement WHERE achievement_id = #{id}")
    ResearchAchievement selectById(String id);

    // 根据学生ID查询
    @Select("SELECT * FROM researchachievement WHERE student_id = #{studentId}")
    List<ResearchAchievement> selectByStudentId(String studentId);

    // 添加科研成果
    @Insert("INSERT INTO researchachievement (achievement_id, student_id, type, title, " +
            "category, status, publish_date, score, is_representative, co_authors) " +
            "VALUES (#{achievementId}, #{studentId}, #{type}, #{title}, " +
            "#{category}, #{status}, #{publishDate}, #{score}, #{isRepresentative}, #{coAuthors})")
    int insert(ResearchAchievement achievement);

    // 更新科研成果
    @Update("UPDATE researchachievement SET " +
            "student_id = #{studentId}, type = #{type}, title = #{title}, " +
            "category = #{category}, status = #{status}, publish_date = #{publishDate}, " +
            "score = #{score}, is_representative = #{isRepresentative}, co_authors = #{coAuthors} " +
            "WHERE achievement_id = #{achievementId}")
    int update(ResearchAchievement achievement);

    // 删除科研成果
    @Delete("DELETE FROM researchachievement WHERE achievement_id = #{id}")
    int delete(String id);
}